package com.example.mybatis.mapper;

import com.example.mybatis.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper2 {
    @Select("select * from `user_info` where id = #{id}")
    List<UserInfo> selectById(Integer id);

    @Select("select * from `user_info` where age = #{age} and gender = #{gender}")
    List<UserInfo> selectByAgeAndGender(Integer age,Integer gender);

    @Select("select * from `user_info` where age = #{age} and gender = #{gender}")
    List<UserInfo> selectByAgeAndGender2(Integer age, @Param("gender")Integer gen);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username,`password`,age) values (#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Insert("insert into user_info (username,`password`,age) values (#{userInfo.username},#{userInfo.password},#{userInfo.age})")
    Integer insertUser2(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from user_info where id = #{id}")
    Integer deleteUser(Integer id);

    @Update("update user_info set gender = #{gender},delete_flag = #{deleteFlag} where id = #{id}")
    Integer updateUser(UserInfo userInfo);

    @Update("<script> update user_info" +
            "        <set>" +
            "            <if test='gender!=null'>" +
            "                gender = #{gender}," +
            "            </if>" +
            "            <if test='deleteFlag!=null'>" +
            "                delete_flag = #{deleteFlag}" +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    Integer updateUserByCondition(UserInfo userInfo);
}








































